import React from 'react'
// ===================================================================== 
import onSubmit from './js/onSubmit'
// ===================================================================== 
const { $fn, $Lazy } = window
// ===================================================================== 
const SubmitForm = $Lazy.state(()=>import('#cpt/form/submit-form'))
// ===================================================================== 
const Index = function(option){
	const opt = {
		clear:true,
		refresh:true,
		...option
	}
	const { data, onRef, onForm, onLoad, query, back = true, children, onOkClick, enter=true } = opt
	const { formData, submitLoading } = this.state
	const _data = data || formData
	return <SubmitForm
		data 		= { _data }
		loading 	= { submitLoading }
		onOkClick	= { onOkClick }
		hideButton
		{...option}
		enter 		= { enter }
		onSubmit 	= { param => onSubmit.call(this,{ ...option, param, query }) }
		onRef 		= { onForm ? null : ref => {this.formRef = ref; onRef?.(ref) } }
		onForm		= { onForm ? ref => { this.formRef=ref; onForm?.(ref) } : ref => {
				this?.onForm?.(ref, formData)
				onLoad?.(ref)
			}
		}
		onClose	 = { ()=>{
			if(back){ $fn.back(this) }
		} }
		children  = { $fn.hasArray(_data) ? children : <div className='h50 g9 tc f12 mb10 w'>表单数据不存在,请检查!!!</div> }
	/>
}
export default Index